//
//  LTEllipseView.m
//  LearnTeacher
//
//  Created by zyl on 2024/4/22.
//

#import "LTEllipseView.h"

@implementation LTEllipseView


// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
//- (void)drawRect:(CGRect)rect {
//    CGContextRef content = UIGraphicsGetCurrentContext();
//    CGPathAddEllipseInRect(CGContextFillPath(content), CGAffineTransformScale(1, 1, 1), CGRectMake(0, 0, rect.size.width, rect.size.height/2.0))
//}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        // gradient
        
        CAGradientLayer *gl2 = [CAGradientLayer layer];
        gl2.frame = CGRectMake(0,0,frame.size.width,15);
        gl2.startPoint = CGPointMake(0.5, 0);
        gl2.endPoint = CGPointMake(0.5, 1);
        gl2.colors = @[(__bridge id)[UIColor colorWithRed:121/255.0 green:171/255.0 blue:255/255.0 alpha:1.0].CGColor, (__bridge id)[UIColor colorWithRed:41/255.0 green:121/255.0 blue:255/255.0 alpha:1.0].CGColor];
        gl2.locations = @[@(0), @(1.0f)];
        CAShapeLayer *shapeLayer2 = [CAShapeLayer layer];
        shapeLayer2.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, frame.size.width, 15)].CGPath;
        gl2.mask = shapeLayer2;
        
        
        CAGradientLayer *gl = [CAGradientLayer layer];
        gl.frame = CGRectMake(0,7.5,frame.size.width,frame.size.height - 7.5);
        gl.startPoint = CGPointMake(0.5, 0);
        gl.endPoint = CGPointMake(0.5, 1);
        gl.colors = @[(__bridge id)[UIColor colorWithRed:121/255.0 green:171/255.0 blue:255/255.0 alpha:1.0].CGColor, (__bridge id)[UIColor colorWithRed:41/255.0 green:121/255.0 blue:255/255.0 alpha:1.0].CGColor];
        gl.locations = @[@(0), @(1.0f)];
        CAShapeLayer *shapeLayer = [CAShapeLayer layer];
        shapeLayer.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0,0,frame.size.width,frame.size.height - 7.5) byRoundingCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight cornerRadii:CGSizeMake(8, 8)].CGPath;
        gl.mask = shapeLayer;
        [self.layer addSublayer:gl];
        [self.layer addSublayer:gl2];
       
    }
    return self;
}

@end
